<template>
	<view class="page">
		<view class="list flex_center" v-for="(item,index) in list" :key="index">
			<view class="left flex_center">
				<view class="avatar">
					<image :src="item.avatar" mode="aspectFill"></image>
				</view>
				<view class="text flex_c">
					<view class="hidden">{{ item.nickname || '' }}</view>
					<uni-dateformat :date="item.apply_time * 1000" format="yyyy.MM.dd hh:mm"></uni-dateformat>
				</view>
			</view>
			<view class="right flex_center">
				<view class="btn accept flex_r_around" @click="beforeAccept(item)">
					<text>拒绝</text>
				</view>
				<view class="btn agree flex_r_around" @click="onAgree(item)">
					<text>同意</text>
				</view>
			</view>
		</view>
		
		<view style="background: #FFF;" v-if="!list.length && total == 0">
			<empty></empty>
		</view>
		<view style="background: #FFF;" v-if="!list.length && total == 1">
			<loading></loading>
		</view>

		<u-popup :show="show" @close="show = false" mode="center" round="40rpx">
			<view class="modal">
				<view class="modal_title flex_r_between">
					<text>拒绝原因</text>
					<u-icon name="close-circle" color="#CCCCCC" size="48rpx" @click="show = false"></u-icon>
				</view>

				<view class="modal_textarea">
					<textarea placeholder="请输入" placeholder-class="input-placeholder" v-model="check_content"></textarea>
				</view>

				<view class="modal_btn flex_r_around" @click="onAccept">
					<text>确定</text>
				</view>

			</view>
		</u-popup>
	</view>
</template>

<script>
	import empty from '@/compentents/empty/empty.vue';
	import loading from '@/compentents/loading/loading.vue';
	export default {
		name: 'apply',
		props: {
			circle_id: {
				type: Number,
				default: 0,
			}
		},
		components: {
			empty,
			loading
		},
		data() {
			return {
				show: false,

				list: [],
				total: 1,
				page: 1,
				
				user_id: 0,
				
				check_content: '',
			}
		},
		methods: {
			getList() {
				this.$get('/circle.circle_member/getJoinLog', {
					circle_id: this.circle_id
				}).then(res => {
					this.total = res.data.total;
					this.list.push(...res.data.data);
				})
			},
			
			refList() {
				this.list = [];
				this.total = 1;
				this.page = 1;
				this.getList();
			},
			
			beforeAccept(item){
				this.user_id = item.user_id;
				this.show = true;
			},
			
			onAccept(){
				this.show = false;
				this.$post('/circle.circle_member/checkJoinLog',{
					circle_id: this.circle_id,
					user_id: this.user_id,
					status: 3,
					check_content: this.check_content,
				}).then(res=>{
					this.$util.msg(res.msg);
					this.refList();
				})
			},
			
			onAgree(item){
				this.$post('/circle.circle_member/checkJoinLog',{
					circle_id: this.circle_id,
					user_id: item.user_id,
					status: 2,
				}).then(res=>{
					this.$util.msg(res.msg);
					this.refList();
				})
			},
			
			onReach(){
				if(this.total > this.list.length){
					this.page++;
					this.getList();
				}
			},
			
		},

		created() {
			this.getList();
		}
	}
</script>

<style scoped lang="less">
	.page {
		padding: 0 32rpx;
	}

	.list {
		padding: 28rpx 0;
		overflow: hidden;

		.left {
			flex: 1;
			overflow: hidden;

			.avatar {
				width: 96rpx;
				height: 96rpx;
				border-radius: 48rpx;
				overflow: hidden;
				margin-right: 24rpx;

				image {
					width: 96rpx;
					height: 96rpx;
				}
			}

			.text {
				flex: 1;
				overflow: hidden;
				align-items: flex-start;

				view {
					font-weight: 500;
					font-size: 32rpx;
					color: #131313;
					max-width: 100%;
				}

				text {
					font-size: 24rpx;
					color: #666666;
				}

			}
		}

		.right {
			.btn {
				width: 96rpx;
				height: 40rpx;
				border-radius: 20rpx;
				margin-left: 16rpx;

				text {
					font-size: 24rpx;
				}
			}

			.agree {
				border: 2rpx solid #1FC129;

				text {
					color: #1FC129;
				}
			}

			.accept {
				border: 2rpx solid #FD2A53;

				text {
					color: #FD2A53;
				}
			}
		}



	}

	.modal {
		width: 616rpx;
		background: #FFFFFF;
		border-radius: 40rpx;
		padding: 34rpx 16rpx 38rpx 32rpx;

		.modal_title {
			text {
				font-weight: 500;
				font-size: 36rpx;
				color: #131313;
				line-height: 50rpx;
			}
		}

		.modal_textarea {
			width: 552rpx;
			height: 208rpx;
			background: #F7F7F7;
			border-radius: 16rpx;
			padding: 24rpx;
			margin: 32rpx 0;
			overflow: hidden;

			textarea {
				font-size: 28rpx;
				color: #333;
				line-height: 36rpx;
			}
		}

		.modal_btn {
			width: 320rpx;
			height: 88rpx;
			background: #FD2A53;
			border-radius: 44rpx;
			margin: 0 auto;

			text {
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}

	}
</style>